package com.lw.vue_shop_server.service.impl;

import com.lw.vue_shop_server.mapper.CategoryMapper;
import com.lw.vue_shop_server.po.Category;
import com.lw.vue_shop_server.service.CategoryService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Service
public class CategoryServiceImpl implements CategoryService {

    @Autowired
    public CategoryMapper categoryMapper;

    @Override
    public Map getCategories(Integer pagenum, Integer pagesize) {
        Map<String,Object> result = new HashMap<>();
        Map<String,Object> data = new HashMap<>();
        Map<String,Object> meta = new HashMap<>();
        List<Category> categories = null;
        if(pagenum!=null){
            categories=categoryMapper.getCategories(0,500);
        }else {
            categories=categoryMapper.getCategories(pagenum,pagesize);
        }
        if (categories!=null){
            if(pagenum!=null&&pagesize!=null){
                data.put("total",categoryMapper.getCategoryNum());
                data.put("pagenum",pagenum);
                data.put("pagesize",pagesize);
                data.put("result",categories);
                result.put("data",data);
            }else {
                result.put("data",categories);
            }
            meta.put("msg","获取成功");
            meta.put("status",200);
        }else {
            meta.put("msg","获取失败");
            meta.put("status",500);
        }
        result.put("meta",meta);
        return result;
    }
}
